<?php
if (!defined('Copyright') && Copyright != 'Author QQ: 765858558') exit('Author QQ: 765858558'); if (!defined('ROOT_PATH')) exit('Author QQ: 765858558'); $logo="诚信娱乐"; class DB 
{
	private $dbHost = 'localhost';
	private $dbUser = 'root';
	private $dbPwd = 'cdit_&*(';
	private $dbName = 'oa';
	public $conn = NULL;
	public function DB() 
	{
		$this->connect();
	}
	public function close() 
	{
	}
	private function connect () 
	{
		global $db;
		if(!isset($db)) 
		{
			$this->conn = mysql_connect($this->dbHost, $this->dbUser, $this->dbPwd) or die ("Could not connect");
			mysql_select_db($this->dbName, $this->conn) or die ("Could not selectDB");
			mysql_set_charset('utf8', $this->conn);
			register_shutdown_function(array(&$this, 'close'));
		}
		else $this->conn=$db->conn;
		return $this->conn;
	}
	public function query ($sql, $parameter) 
	{
		$result = NULL;
		$query = mysql_query ($sql,$this->conn) or die ("Invalid query：".$sql);
		switch ($parameter) 
		{
			case 0 : while (!!$row = mysql_fetch_row($query)) 
			{
				$result[] = $row;
			}
			break;
			case 1 : while (!!$row = mysql_fetch_assoc($query))
			{
				$result[] = $row;
			}
			break;
			case 2 : $result = mysql_affected_rows($this->conn);
			break;
			case 3 : $result = mysql_num_rows($query);
			break;
			case 4 : $result = mysql_insert_id($this->conn);
			break;
			case 5 : while (!!$row = mysql_fetch_field($query))
			{
				$result[] = $row->name;
			}
		}
		return $result;
	}
	public function GetTables() 
	{
		$database = $this->dbName;
		$tables = mysql_query("SHOW TABLES FROM $database");
		while (!!$row = mysql_fetch_row($tables))
		{
			$result[] = $row[0];
		}
		return $result;
	}
	public function Select ($param, $from, $limit, $where=null, $parameter=1) 
	{
		$sql = $where == null ? " SELECT {$param}
	FROM {$from} LIMIT = $limit ": " SELECT {$param} FROM {$from} WHERE {$where} LIMIT $limit "; return $this->query($sql, $parameter); } public function Update ($set, $from, $where, $limit) { $sql = " UPDATE {$from} SET {$set} WHERE {$where} LIMIT $limit"; return $this->query($sql, 2); } } ?>